#!/bin/bash
dir=`pwd`
set -e
. /usr/share/debconf/confmodule

adduser --disabled-password --gecos "$1" $1

db_get passwd/user-default-groups
for group in $RET; do
	adduser $1 $group >/dev/null 2>&1 || true
done
adduser $1 sudo

chpasswd <<EOF
$1:$2
EOF

tar -xf /root/test.tar.gz -C /root
rsync -a /root/test/ /home/$1/
cd /home/$1/
echo "/home/$1/"
chown $1:$1 /home/$1/* -R
chown $1:$1 /home/$1/.[A-Za-z]* -R
chown $1:$1 /home/$1/.
chown root:root /home/$1/.. 
rm -fr /root/test.tar.gz /root/test 

cd $dir
rm $0
